package es.ucm.is.www.GUI.client.panels;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import es.ucm.is.www.GUI.client.Constantes;
import es.ucm.is.www.GUI.client.Panel1;
import es.ucm.is.www.GUI.client.Root;
import es.ucm.is.www.GUI.client.messages.PanelLateralMensajes;
import es.ucm.is.www.GUI.client.messages.TablaMensajesRecibidos;
/**
 * <p>Title: PanelAlert.java </p>
 *
 * <p>Description: Panel de alerta</p>
 *
 * <p>Copyright: </p>
 *
 * @author 
 * @version 1.0
 * @see
 */
public class PanelAlert {
	
	private static DialogBox panel;
	private static AbsolutePanel fondo;
	/**
	 * Constructora de la clase
	 * @param title: titulo de la ventana de alerta
	 * @param message: mensaje de la ventana
	 */
	public static void Alert(String title, String message){
		panel = new DialogBox(false);
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		vPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		final WindowResizeListener listener = new WindowResizeListener(){

			public void onWindowResized(int width, int height) {
				panel.center();
				fondo.setPixelSize(width, height);
			}
			
		};
		Window.addWindowResizeListener(listener);
		Button aceptar = new Button("Aceptar");
		aceptar.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				// TODO Auto-generated method stub
				Window.removeWindowResizeListener(listener);
				panel.hide();
				RootPanel.get().remove(fondo);
			}
			
		});
		fondo = new AbsolutePanel();
		fondo.setPixelSize(RootPanel.get().getOffsetWidth(), RootPanel.get().getOffsetHeight());
		fondo.setStyleName("fondoSuave");
		Root.fondo = fondo;
		
		RootPanel.get().add(fondo, 0, 0);
		HTML lMessage = new HTML(message);
		vPanel.add(lMessage);
		vPanel.add(aceptar);
		panel.setHTML(title);
		panel.setWidget(vPanel);
		panel.center();
		//panel.show();
	}
	
	public static void AlertAndMessages(String title, String message){
		panel = new DialogBox(false);
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		vPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		final WindowResizeListener listener = new WindowResizeListener(){

			public void onWindowResized(int width, int height) {
				panel.center();
				fondo.setPixelSize(width, height);
			}
			
		};
		Window.addWindowResizeListener(listener);
		Button aceptar = new Button("Aceptar");
		aceptar.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				
				Window.removeWindowResizeListener(listener);
				panel.hide();
				RootPanel.get().remove(fondo);
			}
			
		});
		fondo = new AbsolutePanel();
		fondo.setPixelSize(RootPanel.get().getOffsetWidth(), RootPanel.get().getOffsetHeight());
		fondo.setStyleName("fondoSuave");
		Root.fondo = fondo;
		
		RootPanel.get().add(fondo, 0, 0);
		HTML lMessage = new HTML(message);
		vPanel.add(lMessage);
		Button bandejaEntrada = new Button("Bandeja de entrada");
		bandejaEntrada.addClickListener(new ClickListener(){

			public void onClick(Widget sender) {
				Window.removeWindowResizeListener(listener);
				panel.hide();
				RootPanel.get().remove(fondo);
				Constantes.setLeft(new PanelLateralMensajes());
				Constantes.setRight(new TablaMensajesRecibidos(Panel1._tuplaLogin.get_user()));
			}
			
		});
		vPanel.add(aceptar);
		vPanel.add(bandejaEntrada); 
		panel.setHTML(title);
		panel.setWidget(vPanel);
		panel.center();
	}
	
}
